package org.example.config;


import org.example.service.*;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan(basePackages = "org.example")
public class AppConfig {
    @Bean
    @ConditionalOnProperty(name = "order.type", havingValue = "standard")
    public OrderProcessor standardOrderProcessor() {
        return new StandardOrderProcessor();
    }

    @Bean
    @ConditionalOnProperty(name = "order.type", havingValue = "premium")
    public OrderProcessor premiumOrderProcessor() {
        return new PremiumOrderProcessor();
    }

    @Bean
    @ConditionalOnProperty(name = "payment.method", havingValue = "alipay")
    public PaymentService alipayPaymentProcessor() {
        return new AlipayPaymentService();
    }

    @Bean
    @ConditionalOnProperty(name = "payment.method", havingValue = "creditCard")
    public PaymentService creditCardPaymentProcessor() {
        return new CreditCardPaymentService();
    }

    @Bean
    public OrderService orderService(OrderProcessor orderProcessor, PaymentService paymentService) {
        return new OrderServiceImpl(orderProcessor, paymentService);
    }
}
